/*
Automatic clinic tests using a robot arm.
Copyright (C) 2010  CIC-CPC, CHU Gabriel Montpied
All other trademarks, logos and copyrights are the property
of their respective owners.

This file is part of cpc-painbot.

cpc-painbot is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

cpc-painbot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with cpc-painbot.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "seuil/determination.h"
#include "seuil/methode.h"
#include "stimulation/stimulateur.h"

namespace seuil {

QString Determination::typeToString(Type type)
{
    QString chaine(tr("Seuil de "));
    switch (type) {
        case Douleur:     chaine.append(tr("Douleur"));     break;
        case Sensibilite: chaine.append(tr("Sensibilité")); break;
        case Tolerance:   chaine.append(tr("Tolérance"));   break;

        default: break;
    }

    return chaine;
}

Determination *Determination::creer(Type type, Methode::Type type_methode,
                                    Stimulateur::Type type_stimulateur, QObject *parent)
{
    Determination *determination = new Determination(parent);
    seuil::Methode *methode = seuil::Methode::creer(type_methode, determination);

    if ( methode != 0 ) {
        Stimulateur *stimulateur = Stimulateur::creer(type_stimulateur, determination);

        if ( stimulateur != 0 ) {
            determination->setType(type);
            determination->setMethode(methode);
            determination->setStimulateur(stimulateur);

            // Connexions des signaux.
        } else {
            qCritical("Determination::creer : Le Stimulateur demande n'existe pas.");
            methode->deleteLater();
        }
    } else
        qCritical("Determination::creer : La Methode demandee n'existe pas.");

    if ( determination->methode() == 0 || determination->stimulateur() == 0 ) {
        determination->deleteLater();
        determination = 0;
    }

    return determination;
}

Determination::Determination(QObject *parent) :
    QObject(parent),
    methode_(0),
    stimulateur_(0)
{
}

void Determination::preparer()
{
    Q_ASSERT(stimulateur() != 0);
    Q_ASSERT(methode() != 0);

    methode()->preparer(this);
}

} // namespace seuil.
